package com.example.commoditymanagementsystemspringboot.config;

import com.example.commoditymanagementsystemspringboot.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 实现WebMvcConfigurer接口，扩展MVC功能
 *
 * @author 雷族
 */
@Configuration
public class MyMVCconfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    // 添加拦截器管理
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> ex = new ArrayList<>();
        //登录注册和登录注册跳转请求放行
        ex.add("/toLogin.action");
        ex.add("/user/login.action");
        ex.add("/toRegister.action");
        ex.add("/user/register.action");
        registry.addInterceptor(loginInterceptor).addPathPatterns("/*.action").excludePathPatterns(ex);
    }
}
